package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import cn.sumpu.app.guoguojie.dao.StrollDao;
import cn.sumpu.app.guoguojie.domain.Stroll;
import cn.sumpu.app.guoguojie.domain.StrollClass;
import cn.sumpu.app.guoguojie.domain.StrollGoods;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class StrollDaoImpl extends SqlSessionDaoSupport implements StrollDao{
	
	//
	@Override
	public void insertStroll(Stroll stroll) throws AppBusinessException {
		try {
			getSqlSession()
			.insert("cn.sumpu.app.guoguojie.persistence.StrollMapper.insertStroll",
					stroll);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertStroll rushdatabase failure.", e);
			}
			throw new AppBusinessException("insertStroll rushdatabase failure.", e);
		}
		
	}
	//
	@Override
	public void insertStrollClass(StrollClass strollClass) throws AppBusinessException {
		try {
			getSqlSession()
			.insert("cn.sumpu.app.guoguojie.persistence.StrollMapper.insertStrollClass",
					strollClass);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertStrollClass rushdatabase failure.", e);
			}
			throw new AppBusinessException("insertStrollClass rushdatabase failure.", e);
		}
		
	}
	
	//查询所有逛街专辑
	@SuppressWarnings("unchecked")
	@Override
	public List<Stroll> selectStrollList()throws AppBusinessException {
		try {
			return getSqlSession().selectList(
					"cn.sumpu.app.guoguojie.persistence.StrollMapper.selectStrollList");
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("selectStrollList database failure.", e);
			}
			throw new AppBusinessException("selectStrollList database failure.", e);
		}
	}
	//查询某一专辑所有分类
	@SuppressWarnings("unchecked")
	@Override
	public List<StrollClass> selectStrollClassList(String strollId)throws AppBusinessException {
		try {
			return getSqlSession().selectList(
					"cn.sumpu.app.guoguojie.persistence.StrollMapper.selectStrollClassList",strollId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("selectStrollList database failure.", e);
			}
			throw new AppBusinessException("selectStrollList database failure.", e);
		}
	}
	
	
	//查询专辑详情
	@Override
	public Stroll selectStroll(String strollId)throws AppBusinessException{
		try {
			return (Stroll)getSqlSession().selectOne(
					"cn.sumpu.app.guoguojie.persistence.StrollMapper.selectStroll",
					strollId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("selectStroll database failure.", e);
			}
			throw new AppBusinessException("selectStroll database failure.", e);
		}
	}
	//查询分类详情
	@Override
	public StrollClass selectStrollClass(String classId)throws AppBusinessException{
		try {
			return (StrollClass)getSqlSession().selectOne(
					"cn.sumpu.app.guoguojie.persistence.StrollMapper.selectStrollClass",
					classId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("selectStrollClass database failure.", e);
			}
			throw new AppBusinessException("selectStrollClass database failure.", e);
		}
	}
	
	//更新专辑
	@Override
	public void updateStrollById(Stroll stroll)throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.guoguojie.persistence.StrollMapper.updateStrollById",
							stroll);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateStrollById database failure.", e);
			}
			throw new AppBusinessException("updateStrollById database failure.", e);
		}
	}
	//删除
	@Override
	public void deleteStrollById(String identifier)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollById",
							identifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	//根据专辑号删除商品
	@Override
	public void deleteStrollGoodsByStrollId(String strollId)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollGoodsByStrollId",
							strollId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	//根据专辑号删除分类
	@Override
	public void deleteStrollClassByStrollId(String strollId)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollClassByStrollId",
							strollId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	
	
	//更新分类
	@Override
	public void updateStrollClassById(StrollClass strollClass)throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.guoguojie.persistence.StrollMapper.updateStrollClassById",
							strollClass);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateStrollClassById database failure.", e);
			}
			throw new AppBusinessException("updateStrollClassById database failure.", e);
		}
	}
	//更新商品
	@Override
	public void updateStrollGoodsById(StrollGoods strollGoods)throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.guoguojie.persistence.StrollMapper.updateStrollGoodsById",
							strollGoods);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateStrollClassById database failure.", e);
			}
			throw new AppBusinessException("updateStrollClassById database failure.", e);
		}
	}
	
	//删除分类
	@Override
	public void deleteStrollClassById(String identifier)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollClassById",
							identifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	//根据分类号删除商品
	@Override
	public void deleteStrollGoodsByClassId(String classId)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollGoodsByClassId",
							classId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	
	//删除商品
	@Override
	public void deleteStrollGoodsById(String identifier)throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.StrollMapper.deleteStrollGoodsById",
							identifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteStrollById database failure.", e);
			}
			throw new AppBusinessException("deleteStrollById database failure.", e);
		}
	}
	
	
	//添加商品
	@Override
	public void insertStrollGoods(StrollGoods strollGoods) throws AppBusinessException {
		try {
			getSqlSession()
			.insert("cn.sumpu.app.guoguojie.persistence.StrollMapper.insertStrollGoods",
					strollGoods);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertStrollGoods rushdatabase failure.", e);
			}
			throw new AppBusinessException("insertStrollGoods rushdatabase failure.", e);
		}
		
	}
	//查看商品详情
	@Override
	public StrollGoods selectStrollGoods(String goodsId)throws AppBusinessException{
		try {
			return (StrollGoods)getSqlSession().selectOne(
					"cn.sumpu.app.guoguojie.persistence.StrollMapper.selectStrollGoods",
					goodsId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("selectStrollClass database failure.", e);
			}
			throw new AppBusinessException("selectStrollClass database failure.", e);
		}
	}
	
	
}
